import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/index'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/home/index'),
        meta: {title: '我的首页', icon: 'el-icon-s-home'}
      },
      {
        path: 'chart',
        name: 'Chart',
        component: () => import('@/views/chart/index'),
        meta: {title: 'CHART', icon: 'el-icon-star-off'}
      },
      {
        path: '/form',
        name: 'Form',
        component: Layout,
        redirect: '/form/form1',
        meta: {title: 'FORM', icon: 'el-icon-star-off'},
        children: [
          {
            path: 'form1',
            name: 'form1',
            component: () => import('@/views/form/form1'),
            meta: { title: 'Table', icon: 'table' }
          },
          {
            path: 'form2',
            name: 'form2',
            component: () => import('@/views/form/form2'),
            meta: { title: 'Tree', icon: 'tree' }
          }
        ]
      }
    ]
  },
]
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
